home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / clock01.arc / CLOCK.ASM next >
Assembly Source File  |  1991-03-20  |  8KB  |  259 lines

  1. ;┌───────────────────────────────────────────────────────────┐
  2. ;│ CLOCK.ASM                                                 │
  3. ;│ Dan Travison                                              │
  4. ;├───────────────────────────────────────────────────────────┤
  5. ;│ Clock uses fields for the positions of each 'LCD'         │
  6. ;│ position.                                                 │
  7. ;│                                                           │
  8. ;│ Fields are 'turned on' by filling the field with a        │
  9. ;│ character. The fields are turned off by writing           │
  10. ;│ 0 to the field (transparent blank).                       │
  11. ;│                                                           │
  12. ;│ Also, the user can press a key to change the fill         │
  13. ;│ character.  Using the ALT key with the numeric            │
  14. ;│ keypad allows the use of translucent blanks               │
  15. ;│ with ALT-255.                                             │
  16. ;│                                                           │
  17. ;└───────────────────────────────────────────────────────────┘
  18.  
  19.             title clock
  20.             page  60,132
  21.  
  22. include     dvapi.inc
  23. include     dvapi.mac
  24.  
  25. code        segment
  26.             assume cs:code,ds:code
  27.             org   0100h
  28.  
  29. entry:      jmp   start
  30.  
  31. numtable    db    01110111b   ;0
  32.             db    01000100b   ;1
  33.             db    00111110b   ;2
  34.             db    01101110b   ;3
  35.             db    01001101b   ;4
  36.             db    01101011b   ;5
  37.             db    01111001b   ;6
  38.             db    01000110b   ;7
  39.             db    01111111b   ;8
  40.             db    01001111b   ;9
  41.  
  42. fldchar     db    1bh,0
  43.             dw    fldcharl-4
  44.             db    0f1h
  45. fldchar_fld db    0
  46. fldchar_chr db    20h
  47. fldcharl    equ   $-fldchar
  48.  
  49. fldoff      db    1bh,0
  50.             dw    fldoffl-4
  51.             db    0f1h
  52. fldoff_num  db    0
  53.             db    0h
  54. fldoffl     equ   $-fldoff
  55.  
  56. @asciiz     panel_name, 'CLOCK.PLB'
  57. @str        pan_entry,'CLOCK'
  58.  
  59. tim         dd    0                    ;timer handle
  60. obq         dd    0
  61. win         dd    0                    ;window handle
  62. key         dd    0                    ;keyboard handle
  63. pan         dd    0                    ;panel handle
  64.  
  65. hour        db    25
  66. min         db    61
  67.  
  68. start:      mov   ax,cs                ;setup data segment
  69.             mov   ds,ax
  70.  
  71.             @call dvpresent            ;check for DESqview
  72.             test  ax,ax
  73.             jz    eoj                  ;if not present, exit
  74.             call  inits                ;get object handles and setup window
  75.             jc    eoj
  76. main:
  77.             call  time                 ;display time
  78.             mov   cx,100               ;1 second delay
  79.             xor   dx,dx                ;clear high word
  80.             @push dxcx                 ;push delay
  81.             @send addto,tim            ;set timer
  82.             @send read,obq             ;wait on timer
  83.             @pop  bxax
  84.             @cmp  key
  85.             jne   main
  86.             @send read,key
  87.             @pop  esdi
  88.             @pop  esdi
  89.             mov   al,byte ptr es:[di]
  90.             mov   fldchar_chr,al
  91.             mov   hour,99
  92.             mov   min,99
  93.             jmp   main                 ;loop indefinitely
  94.  
  95. eoj:
  96.             mov   ah,4ch
  97.             int   21h
  98.  
  99. ;┌───────────────────────────────────────────────────────────┐
  100. ;│ inits: initialization routines                            │
  101. ;│                                                           │
  102. ;│    get/create required handles                            │
  103. ;│    open the panel library                                 │
  104. ;│    apply the CLOCK panel                                  │
  105. ;│    turn off the hardware cursor                           │
  106. ;├───────────────────────────────────────────────────────────┤
  107. ;│ input:                                                    │
  108. ;│  none                                                     │
  109. ;│ output:                                                   │
  110. ;│  none                                                     │
  111. ;└───────────────────────────────────────────────────────────┘
  112.  
  113. inits       proc  near
  114.             @send new,timer            ;get required object handles
  115.             @pop  tim
  116.             @send handle,me
  117.             @pop  win
  118.             @send handle,keyme
  119.             @pop  key
  120.             @send handle,objqme
  121.             @pop  obq
  122.             @send new,panel
  123.             @pop  pan
  124.             mov   si,offset panel_name  ;panel file name
  125.             mov   cx,panel_namel       ;length of file name
  126.             @mov  esdi,pan
  127.             call  pan_open
  128.             jc    inits_end
  129.  
  130.             mov   si,offset pan_entry
  131.             mov   cx,pan_entryl
  132.             @mov  esdi,pan
  133.             call  pan_apply            ;apply the CLOCK panel
  134.             jc    inits_end
  135.             mov   ax,02h
  136.             xor   bx,bx
  137.             @push bxax
  138.             @send subfrom,keyme       ;turn off the hardware cursor
  139. inits_end:
  140.             ret
  141. inits       endp
  142.  
  143. ;┌───────────────────────────────────────────────────────────┐
  144. ;│ get_time: get system time, format for display             │
  145. ;├───────────────────────────────────────────────────────────┤
  146. ;│ input:                                                    │
  147. ;│  none                                                     │
  148. ;│ output:                                                   │
  149. ;│  none                                                     │
  150. ;└───────────────────────────────────────────────────────────┘
  151.  
  152. time        proc  near
  153.             mov   ah,2ch
  154.             int   21h
  155.             push  dx
  156.             push  cx
  157.             mov   al,ch
  158.             cmp   al,hour
  159.             je    time_min
  160.             mov   hour,al
  161.             mov   dh,1
  162.             call  fld_set
  163. time_min:
  164.             pop   ax
  165.             cmp   al,min
  166.             je    time_sec
  167.             mov   min,al
  168.             mov   dh,15
  169.             call  fld_set
  170. time_sec:
  171.             pop   ax
  172.             xchg  ah,al
  173.             mov   dh,29
  174.             call  fld_set
  175.             @send redraw,win
  176. time_end:
  177.             ret
  178. time        endp
  179.  
  180. ;
  181.  
  182. fld_set     proc  near
  183.             aam                        ;divide by 10
  184.             push  ax
  185.             call  fld_test
  186.             pop   ax
  187.             xchg  ah,al
  188.             call  fld_test
  189.             ret
  190. fld_set     endp
  191.  
  192.  
  193. fld_test    proc  near
  194.             call  num_off
  195.             mov   bx,offset numtable
  196.             add   bl,ah
  197.             mov   al,byte ptr [bx]
  198.             mov   ah,1
  199.             mov   cx,7
  200. fld_test_loop:
  201.             test  al,ah
  202.             jz    fld_test_off
  203.             call  fld_char
  204. fld_test_off:
  205.             inc   dh
  206.             shl   ah,1
  207.             loop  fld_test_loop
  208.             ret
  209. fld_test    endp
  210.  
  211. num_off     proc  near
  212.             @push bxax
  213.             push  dx
  214.             mov   cx,7
  215. num_off_loop:
  216.             @push dxcx
  217.             mov   fldoff_num,dh
  218.             xor   dx,dx
  219.             mov   cx,fldoffl
  220.             mov   si,offset fldoff
  221.             @push dssi
  222.             @push dxcx
  223.             @send write,win
  224.             @pop  dxcx
  225.             inc   dh
  226.             loop  num_off_loop
  227.  
  228.             pop   dx
  229.             @pop  bxax
  230.             ret
  231. num_off     endp
  232.  
  233.  
  234. ; dh field number
  235. ; dl character
  236.  
  237. fld_char    proc  near
  238.             @push dxcx
  239.             @push bxax
  240.  
  241.             mov   fldchar_fld,dh
  242.             mov   si,offset fldchar
  243.             mov   cx,fldcharl
  244.             xor   dx,dx
  245.             @push dssi
  246.             @push dxcx
  247.             @send write,win
  248.  
  249.             @pop  bxax
  250.             @pop  dxcx
  251.             ret
  252. fld_char    endp
  253.  
  254. include     pan_open.inc
  255. include     pan_appl.inc
  256.  
  257. code        ends
  258.             end   entry
  259.